package com.group3.hospital.shiro;/*
 *@author 时崎
 * 2021/12/30
 */

import com.group3.hospital.bean.Admin;
import com.group3.hospital.mapper.AdminMapper;
import org.apache.shiro.authc.AuthenticationException;
import org.apache.shiro.authc.AuthenticationInfo;
import org.apache.shiro.authc.AuthenticationToken;
import org.apache.shiro.authc.SimpleAuthenticationInfo;
import org.apache.shiro.authz.AuthorizationInfo;
import org.apache.shiro.realm.AuthorizingRealm;
import org.apache.shiro.subject.PrincipalCollection;
import org.apache.shiro.util.ByteSource;

import javax.annotation.Resource;

public class ShiroRealm extends AuthorizingRealm {
    @Resource
    private AdminMapper adminMapper;
    //授权
    @Override
    protected AuthorizationInfo doGetAuthorizationInfo(PrincipalCollection principalCollection){

        return null;
    }
    //认证
    @Override
    protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken authenticationToken) throws AuthenticationException {
        //获得管理员用户名和明文密码
//        String adminName = authenticationToken.getPrincipal().toString();
//        Admin admin = null;


//        // 获得用户名和明文密码
//        String username = authenticationToken.getPrincipal().toString();
////String password = new String(((UsernamePasswordToken)
//        authenticationToken).getPassword());
//        Admin admin = null;
//        try {
//            admin = adminMapper.queryByUsername(username);
//        } catch (Exception e) {
//            e.printStackTrace();
//        }
//        if(admin == null){ // 用户不存在
//            return null;
//        }
//        return new SimpleAuthenticationInfo(
//                username, // 数据库保存的用户名
//                admin.getPassword(), // 数据库保存的密码
//                ByteSource.Util.bytes(admin.getSalt()), //盐
//                getName()
//        );
        return null;
    }
}
